package com.bracketbird.client.gui.club.tournament;


import com.bracketbird.client.gui.club.tournament.rtc.*;
import com.bracketbird.client.model.tournament.*;
import com.bracketbird.clientcore.appcontrol.*;
import com.bracketbird.clientcore.gui.*;
import com.bracketbird.clientcore.style.*;

/**
 *
 */
public class RankingViewPage extends Page<RankingViewPageController> {

    private VerticalComponent content;
    private LabelComponent noRankingAvailable;
    private AllRankingPanel allRankingPanel;

    public RankingViewPage() {
        super();
        content = new VerticalComponent();
        initWidget(content);
    }

    public void init() {
         RTC.getInstance().getTournament().addStateListener(new TournamentListener<TournamentStateChangedEvent>() {
            public void onChange(TournamentStateChangedEvent event) {
                repaint();
            }
        });
        StyleIt.add(content, RTCLayoutFac2.CONTENT);
        content.add(getNoRankingAvailable(), RTCLayoutFac2.h1().margin(0, 0, 30, 0));
        content.add(getAllRankingPanel(), new TextLayout(null, "100%"));
        repaint();
    }

     protected void setSubPageHolder(Page subPage) {
        //ignore
    }

    public AllRankingPanel getAllRankingPanel() {
        if (allRankingPanel == null) {
            allRankingPanel = new AllRankingPanel();
        }
        return allRankingPanel;
    }

    public LabelComponent getNoRankingAvailable() {
        if (noRankingAvailable == null) {
            noRankingAvailable = new LabelComponent("No ranking/position available now. Tournament not startet.");
        }
        return noRankingAvailable;
    }

    public void showNoRankingAvailable() {
        getNoRankingAvailable().setVisible(true);
        getAllRankingPanel().setVisible(false);
    }

    public void showRankingPanel() {
        getAllRankingPanel().setVisible(true);
        getNoRankingAvailable().setVisible(false);
    }



    public void repaint() {
       Tournament t = RTC.getInstance().getTournament();
       if (t.isNotReady()) {
           showNoRankingAvailable();
       }
       else{
           showRankingPanel();
       }
   }

}